<?php

namespace Controller;

use Handler\TPHandler;
use Handler\UserHandler;
use Model\User;
use Handler\LobbyHandler;
use Extension\Tools;

class UserController extends BaseController {
	/**
	 * 微信注册
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_WeChatRegist($clientId, $json) {
		$nick = $json->nick;
		$head = $json->head;
		$sex = $json->sex;
		$openId = $json->openid;
		$unionId = $json->unionid;
		$code = $json->code;
		
		$nick = Tools::mb_FilterEmoji ( $nick );
		
		$tpData = TPHandler::mb_GetInstance ()->mb_WeChatRegistToTP ( $nick, $head, $sex, $openId, $unionId, $code );
		if ($tpData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $tpData->msg );
			return;
		}
		$uData = json_decode ( $tpData->data );
		// 非首次登录，已有玩家数据
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForOpenIdFromDB ( $openId );
		if ($userData == null) {
			// 新用户
			if (UserHandler::mb_GetInstance ()->mb_AddWeChatUserToDB ( $uData->name, $nick, $head, $sex, $openId, $unionId ) === null) {
				$this->mb_OutHttpMessage ( $clientId, ErrCode_Dialog, json_encode ( $this->mb_EncodeDialogData ( ActCode_Tips, '(更新数据库)系统繁忙，请稍候再试!' ) ) );
				return;
			}
			$userData = UserHandler::mb_GetInstance ()->mb_GetUserForOpenIdFromDB ( $openId );
		}
		$name = $uData->name;
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		
		$token = md5 ( $name . time () );
		$userData ['token'] = $token;
		$this->mb_InitUserObject ( $userData );
		$this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
		echo "$name WeChat Regist Login!\n";
	}
	
	/**
	 * 账号注册(HTTP)
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_AccountRegister($clientId, $json) {
		$name = $json->name;
		$basePass = $json->basepass;
		$encPass = md5 ( $basePass );
		$agent = $json->agent;
		$phone = $json->phone;
		
		$name = Tools::mb_FilterEmoji ( $name );
		
		$lobbyInfo = LobbyHandler::mb_GetInstance ()->mb_GetLobbyInfo ( 1 );
		if ($lobbyInfo ['sw_regist'] != '0') {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '注册关闭中' );
			return;
		}
		
		// 判断该帐号是否登录中
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForName ( $name );
		if (isset ( $user )) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '该帐号登陆中' );
			return;
		}
		// 向sfs请求注册
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_RegistToSFS ( $name, '', $basePass, $agent, $phone );
		$sfsData = TPHandler::mb_GetInstance ()->mb_RegistToTP ( $name, '', $basePass, $agent, $phone );
		if ($sfsData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
			return;
		}
		
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForNameFromDB ( $name );
		if ($userData === null) {
			UserHandler::mb_GetInstance ()->mb_DeleteUserToDB ( $name );
		}
		
		UserHandler::mb_GetInstance ()->mb_AddNameUserToDB ( $name, $basePass, $encPass, $phone );
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForNameFromDB ( $name );
		
		if ($lobbyInfo ['sw_login'] != '0') {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '登录关闭中' );
			return;
		}
		
		// 向sfs请求用户数据
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $name );
		// $sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $name );
		// if ($sfsData->state == false) {
		// $this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
		// return;
		// }
		$uData = json_decode ( $sfsData->data );
		
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		
		$token = md5 ( $name . time () );
		$userData ['token'] = $token;
		$this->mb_InitUserObject ( $userData );
		$this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
		echo "$name Account Login!\n";
	}
	/**
	 * 账号登录（HTTP）
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_AccountLogin($clientId, $json) {
		$name = $json->name;
		$encPass = $json->encpass;
		
		$lobbyInfo = LobbyHandler::mb_GetInstance ()->mb_GetLobbyInfo ( 1 );
		if ($lobbyInfo ['sw_login'] != '0') {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '登录关闭中' );
			return;
		}
		
		// 判断该帐号是否登录中
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForName ( $name );
		if (isset ( $user )) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '该帐号登陆中' );
			return;
		}
		
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForNameFromDB ( $name );
		if ($userData === false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '该用户不存在' );
			return;
		}
		
		if ($userData ['status'] != 0) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '服务器已关闭' );
			return;
		}
		
		if ($encPass != $userData ['encpass']) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '用户名或密码错误' );
			return;
		}
		
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_LoginToSFS ( $name, $userData ['basepass'] );
		$sfsData = TPHandler::mb_GetInstance ()->mb_LoginToTP ( $name, $userData ['basepass'] );
		if ($sfsData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
			return;
		}
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $name );
		// $sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $name );
		// if ($sfsData->state == false) {
		// $this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
		// return;
		// }
		$uData = json_decode ( $sfsData->data );
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		$token = md5 ( $name . time () );
		$userData ['token'] = $token;
		$this->mb_InitUserObject ( $userData );
		$this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
		echo "$name Account Login!\n";
	}
	/**
	 * 微信登录(HTTP)
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_WechatLogin($clientId, $json) {
		$openId = $json->openid;
		$unionId = $json->unionid;
		$nick = $json->nick;
		$head = $json->head;
		$sex = $json->sex;
		
		$nick = Tools::mb_FilterEmoji ( $nick );
		
		// 判断该帐号是否登录中
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForOpenId ( $openId );
		if (isset ( $user )) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Logining, ErrMsg_Logining );
			return;
		}
		
		$tpData = TPHandler::mb_GetInstance ()->mb_CheckWeChatAccountToTp ( $openId );
		if ($tpData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $tpData->msg );
			return;
		}
		$data = json_decode ( $tpData->data );
		if ($data->result == false) {
			// 首次登录，输入邀请码
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Custom, json_encode ( array (
					'nick' => $nick,
					'head' => $head,
					'sex' => $sex,
					'openid' => $openId,
					'unionid' => $unionId 
			) ) );
			return;
		}
		$tpData = TPHandler::mb_GetInstance ()->mb_WeChatLoginToTP ( $nick, $head, $sex, $openId, $unionId );
		if ($tpData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $tpData->msg );
			return;
		}
		$uData = json_decode ( $tpData->data );
		
		// 非首次登录，已有玩家数据
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForOpenIdFromDB ( $openId );
		if ($userData == null) {
			// 新用户
			if (UserHandler::mb_GetInstance ()->mb_AddWeChatUserToDB ( $uData->name, $nick, $head, $sex, $openId, $unionId ) === null) {
				$this->mb_OutHttpMessage ( $clientId, ErrCode_Dialog, json_encode ( $this->mb_EncodeDialogData ( ActCode_Tips, '(更新数据库)系统繁忙，请稍候再试!' ) ) );
				return;
			}
			$userData = UserHandler::mb_GetInstance ()->mb_GetUserForOpenIdFromDB ( $openId );
		}
		$name = $uData->name;
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		
		$token = md5 ( $name . time () );
		$userData ['token'] = $token;
		$this->mb_InitUserObject ( $userData );
		$this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
		echo "$name WeChat Login!\n";
	}
	// /**
	// * 手机号码登录(HTTP)
	// *
	// * @param unknown $clientId
	// * @param unknown $json
	// */
	// public function mb_PhoneLogin($clientId, $json) {
	// $phone = $json->phone;
	// $user = UserHandler::mb_GetInstance ()->mb_GetUserForPhone ( $phone );
	// if (isset ( $user )) {
	// $this->mb_OutHttpMessage ( $clientId, ErrCode_Logining, ErrMsg_Logining );
	// return;
	// }
	// $userData = UserHandler::mb_GetInstance ()->mb_GetUserForPhoneFromDB ( $phone );
	// if ($userData === false) {
	// $this->mb_OutHttpMessage ( $clientId, ErrCode_Dialog, json_encode ( $this->mb_EncodeDialogData ( ActCode_Tips, '系统繁忙，请稍候再试!' ) ) );
	// return;
	// }
	// if (isset ( $userData ) == false) {
	// // 新用户
	// $name = Tools::mb_RandStr ( 6, 'UPNUM' );
	// if (UserHandler::mb_GetInstance ()->mb_AddPhoneUserToDB ( $name, $phone ) === null) {
	// $this->mb_OutHttpMessage ( $clientId, ErrCode_Dialog, json_encode ( $this->mb_EncodeDialogData ( ActCode_Tips, '系统繁忙，请稍候再试!' ) ) );
	// return;
	// }
	// $userData = UserHandler::mb_GetInstance ()->mb_GetUserForOpenIdFromDB ( $openId );
	// } else {
	// $name = $userData ['name'];
	// }
	// $token = md5 ( $name . time () );
	// $userData ['token'] = $token;
	// $this->mb_InitUserObject ( $userData );
	// $this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
	// echo "$name Phone Login!\n";
	// }
	/**
	 * 持久化登录(HTTP)
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_TokenLogin($clientId, $json) {
		$token = $json->token;
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForToken ( $token );
		if (isset ( $user )) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, '该帐号登陆中' );
			return;
		}
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForTokenFromDB ( $token );
		if ($userData === false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		//
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_LoginToSFS ( $userData ['name'], $userData ['basepass'] );
		$sfsData = TPHandler::mb_GetInstance ()->mb_LoginToTP ( $name, $userData ['basepass'] );
		if ($sfsData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
			return;
		}
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $userData ['name'] );
		$sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $name );
		if ($sfsData->state == false) {
			$this->mb_OutHttpMessage ( $clientId, ErrCode_Toast, $sfsData->msg );
			return;
		}
		$uData = json_decode ( $sfsData->data );
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		
		$this->mb_InitUserObject ( $userData );
		$this->mb_OutHttpMessage ( $clientId, ErrCode_Normal, $token );
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForToken ( $token );
		$name = $user->m_Name;
		echo "$name Token Login!\n";
	}
	/**
	 * 登录
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_Login($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false)
			return;
		
		$user->m_ClientId = $clientId;
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, json_encode ( $user->mb_GetAllData () ) );
		
		echo $user->m_Name . " Login Get All Data!\n";
	}
	/**
	 * 心跳
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_HeartBeat($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false)
			return;
		
		$platform = $json->platform;
		$lobbyInfo = LobbyHandler::mb_GetInstance ()->mb_GetLobbyInfo ( $platform );
		
		$user->m_HeartBeat = time ();
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, $lobbyInfo ['ver'] );
	}
	/**
	 * 登出
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_Logout($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false)
			return;
		$name = $user->m_Name;
		UserHandler::mb_GetInstance ()->mb_RemoveUser ( $name );
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, ErrMsg_Normal );
		echo "$name Logout!\n";
	}
	/**
	 * 重连
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_ReConnect($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		
		if ($user == false) {
			return;
		}
		$user->m_ClientId = $clientId;
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, ErrMsg_Normal );
		$name = $user->m_Name;
		echo "$name ReConnect!\n";
	}
	/**
	 * 重登录
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_ReLogin($clientId, $json) {
		$name = $json->name;
		$recNo = $json->recno;
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForName ( $name );
		if (isset ( $user )) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		$userData = UserHandler::mb_GetInstance ()->mb_GetUserForNameFromDB ( $name );
		
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $userData ['name'] );
		$sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $name );
		if ($sfsData->state == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
			return;
		}
		$uData = json_decode ( $sfsData->data );
		$userData ['id'] = ( int ) $uData->id;
		$userData ['coin'] = $uData->coin;
		$userData ['agent'] = $uData->code;
		
		$this->mb_InitUserObject ( $userData, $clientId );
		$user = UserHandler::mb_GetInstance ()->mb_GetUserForName ( $name );
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, json_encode ( $user->mb_GetAllData () ) );
		echo "$name mb_ReLogin!\n";
	}
	/**
	 * 获取用户所有数据
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_GetUserAllData($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $name );
		$sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $name );
		if ($sfsData->state == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
			return;
		}
		$uData = json_decode ( $sfsData->data );
		// $user->m_Coin = ( int ) $uData->coin;
		$user->m_Coin = ( double ) $uData->coin;
		
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, json_encode ( $user->mb_GetAllData () ) );
		echo $user->m_Name . "$name  Get User All Data!\n";
	}
	/**
	 * 获取用户数据
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_GetUserData($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_QueryDataToSFS ( $user->m_Name );
		$sfsData = TPHandler::mb_GetInstance ()->mb_QueryDataToTP ( $user->m_Name );
		if ($sfsData->state == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
			return;
		}
		$uData = json_decode ( $sfsData->data );
		// $user->m_Coin = ( int ) $uData->coin;
		$user->m_Coin = ( double ) $uData->coin;
		// $user->m_Coin = ( int ) $sfsData->data [0]->coins;
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, ( string ) $user->m_Coin );
		echo $user->m_Name . " Get User Data!\n";
	}
	/**
	 * 保存用户数据
	 *
	 * @param string $clientId        	
	 * @param json $json        	
	 */
	public function mb_SaveUserData($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$coin = $json->coin;
		$remark = $json->remark;
		
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		
		echo "$user->m_Name ---- $coin \n";
		
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_SaveDataToSFS ( $user->m_Name, $coin, $remark );
		$sfsData = TPHandler::mb_GetInstance ()->mb_SaveDataToTP ( $user->m_Name, $coin, $user->m_GameId, $remark );
		if ($sfsData->state == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
			return;
		}
		
		$user->mb_SaveData ( $coin, $remark, $user->m_GameId );
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, ErrMsg_Normal );
		echo $user->m_Name . " Save Data!\n";
	}
	// /**
	// * 编辑用户信息
	// *
	// * @param string $clientId
	// * @param json $json
	// */
	// public function mb_EditUserInfo($clientId, $json) {
	// $token = $json->token;
	// $recNo = $json->recno;
	// $sex = $json->sex;
	// $con = $json->con;
	// $sign = $json->sign;
	// $loc = $json->loc;
	// $phone = $json->phone;
	// $wechat = $json->wechat;
	// $qq = $json->qq;
	// $email = $json->email;
	// $user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
	// if ($user == false) {
	// $this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
	// return;
	// }
	// $sfsData = SFSHandler::mb_GetInstance ()->mb_SaveUserInfo ( $user->m_Name, $sex, $con, $sign, $loc, $phone, $wechat, $qq, $email );
	// if ($sfsData->state == false) {
	// $this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
	// return;
	// }
	// $user->mb_SaveInfo ( $sex, $con, $sign, $loc, $phone, $wechat, $qq, $email );
	// $this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, '编辑成功' );
	// echo $user->m_Name . " Edit Info!\n";
	// }
	/**
	 *
	 * @param unknown $clientId        	
	 * @param unknown $json        	
	 */
	public function mb_ResetPassword($clientId, $json) {
		$token = $json->token;
		$recNo = $json->recno;
		$pass = $json->pass;
		
		$user = $this->mb_CheckUserIsLogining ( $clientId, $recNo, $token );
		if ($user == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Distance, ErrMsg_Distance );
			return;
		}
		
		$encPass = md5 ( $pass );
		
		// $sfsData = SFSHandler::mb_GetInstance ()->mb_ResetPassword ( $user->m_Name, $pass );
		$sfsData = TPHandler::mb_GetInstance ()->mb_ResetPasswordToTP ( $user->m_Name, $pass );
		if ($sfsData->state == false) {
			$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Toast, $sfsData->msg );
			return;
		}
		
		$user->m_BasePass = $pass;
		$user->m_EncPass = $encPass;
		
		$this->mb_OutTextMessage ( $clientId, $recNo, ErrCode_Normal, '修改成功' );
	}
	
	/**
	 * 实例化一个用户对象
	 *
	 * @param unknown $userData        	
	 */
	private function mb_InitUserObject($userData, $clientId = null) {
		$user = new User ();
		$user->mb_Login ( $clientId, $userData );
		UserHandler::mb_GetInstance ()->mb_AddUser ( $user );
	}
}